const { name } = require('./package');
const publicPath ='http://localhost:7900/';

module.exports = {
  devServer: {
    port: 7900,
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
  },
  configureWebpack: {
    output: {
      library: `${name}-[name]`,
      libraryTarget: 'umd',// 把微应用打包成 umd 库格式
      jsonpFunction: `webpackJsonp_${name}`,
    },
  },
  chainWebpack: (config) => {
    if(process.env.NODE_ENV === 'production'){
      const fontRule = config.module.rule('fonts');
      fontRule.uses.clear();
      fontRule
        .use('file-loader')
        .loader('file-loader')
        .options({
          name: 'fonts/[name].[hash:8].[ext]',
          publicPath
        })
        .end()
      const imgRule = config.module.rule('images');
      imgRule.uses.clear();
      imgRule
        .use('file-loader')
        .loader('file-loader')
        .options({
          name: 'img/[name].[hash:8].[ext]',
          publicPath
        })
        .end()
    }
  },
};